﻿using Quartz;
using Quartz.Impl;

namespace Customer360AutoJob.Jobs
{
    public class JobScheduler
    {
        public static void Start()
        {
            IScheduler scheduler = StdSchedulerFactory.GetDefaultScheduler();
            scheduler.Start();

            IJobDetail jobSendmailCreateDao = JobBuilder.Create<ReturnResultCreateDaoRequest>().Build();

            ITrigger trigger = TriggerBuilder.Create()
                .WithDailyTimeIntervalSchedule
                  (s =>
                     s.WithIntervalInMinutes(5)
                    .OnEveryDay()
                    .StartingDailyAt(TimeOfDay.HourAndMinuteOfDay(15, 25))
                  )
                .Build();

            IJobDetail jobSendmailChangeDao = JobBuilder.Create<ReturnResultChangeDaoRequest>().Build();

            ITrigger triggerSendmailChangeDao = TriggerBuilder.Create()
                .WithDailyTimeIntervalSchedule
                  (s =>
                     s.WithIntervalInMinutes(5)
                    .OnEveryDay()
                    .StartingDailyAt(TimeOfDay.HourAndMinuteOfDay(15, 25))
                  )
                .Build();

            //scheduler.ScheduleJob(jobSendmailCreateDao, trigger);
            //scheduler.ScheduleJob(jobSendmailChangeDao, triggerSendmailChangeDao);

            IJobDetail jobExportFreedom = JobBuilder.Create<ExportFreedomCustomer>().Build();
            ITrigger triggerExportFreedom = TriggerBuilder.Create()
                .WithDailyTimeIntervalSchedule
                  (s =>
                     s.OnEveryDay()
                     .StartingDailyAt(TimeOfDay.HourAndMinuteOfDay(8, 09))
                  )
                .Build();
            scheduler.ScheduleJob(jobExportFreedom, triggerExportFreedom);

            IJobDetail jobExportNeedUpdateInfo = JobBuilder.Create<ExportCustomerNeedUpdateInfo>().Build();
            ITrigger triggerExportNeedUpdateInfo = TriggerBuilder.Create()
                .WithDailyTimeIntervalSchedule
                  (s =>
                     s.OnEveryDay()
                    .StartingDailyAt(TimeOfDay.HourAndMinuteOfDay(8, 06))
                  )
                .Build();
            scheduler.ScheduleJob(jobExportNeedUpdateInfo, triggerExportNeedUpdateInfo);

            IJobDetail jobExportMaturity = JobBuilder.Create<ExportAlertMaturity>().Build();
            ITrigger triggerExportMaturity = TriggerBuilder.Create()
                .WithDailyTimeIntervalSchedule
                  (s =>
                     s.OnEveryDay()
                    .StartingDailyAt(TimeOfDay.HourAndMinuteOfDay(8, 21))
                  )
                .Build();
            scheduler.ScheduleJob(jobExportMaturity, triggerExportMaturity);

            IJobDetail jobExportCustomer = JobBuilder.Create<ExportCustomerInfo>().Build();
            ITrigger triggerExportCustomer = TriggerBuilder.Create()
                .WithDailyTimeIntervalSchedule
                  (s =>
                     s.OnEveryDay()
                    .StartingDailyAt(TimeOfDay.HourAndMinuteOfDay(8, 21))
                  )
                .Build();
            scheduler.ScheduleJob(jobExportCustomer, triggerExportCustomer);
        }
    }
}